package bishi.day07_4_25;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author huweilong
 * @date 2022/04/25 11:16
 **/
public class you_xaio_kuohao {
    public boolean chkParenthesis(String A, int n) {
        // write code here
        if (n % 2 == 1) {
            return false;
        }
        Deque<Character> stack = new ArrayDeque<>();
        for (int i = 0; i < A.length(); i++) {
            char ch = A.charAt(i);
            if (ch != '(' && ch != ')') {
                return false;
            }
            if (ch == '(') {
                stack.push(ch);
            } else if (stack.isEmpty()) {
                return false;
            } else {
                stack.pop();
            }
        }
        return true;
    }
}